package org.example.service.impl;

import org.example.service.CacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author xietll
 * @date 2025/9/25  10:23
 * @description
 */
@Service
public class CacheServiceImpl implements CacheService {
    private static final Logger logger = LoggerFactory.getLogger(CacheServiceImpl.class);
    @Autowired
    private CacheManager  cacheManager;


    public void deleteCache(String cacheName, String key){
        Cache cache = cacheManager.getCache(cacheName);
        if(cache!=null){
            cache.evict(key);
        }
        logger.info("清除缓存 {} 中的键 {}", cacheName, key);
    }
}
